﻿
Public Class Target

    Public Property PK_Target As Integer

    Public Property Descrizione As String

    Public Property TargetImgURLSmall As String

    Public Property TargetImgURLMedium As String

    Public Shared Function LoadFromPk(objpk As Integer) As Target
        Dim Trg As New Target
        Dim sql As String = "SELECT * FROM Target WHERE PK_Target = " & objpk
        Dim ds As New DataSet
        Dim dbO As New DBObject
        ds = dbO.FillDS(sql, Nothing, 1)
        If Not IsNothing(ds) AndAlso Not IsNothing(ds.Tables) AndAlso ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
            Trg.PK_Target = objpk
            If Not IsDBNull(ds.Tables(0).Rows(0).Item("Descrizione").ToString) Then
                Trg.Descrizione = ds.Tables(0).Rows(0).Item("Descrizione").ToString
            End If
            If Not IsDBNull(ds.Tables(0).Rows(0).Item("TargetImgURLSmall").ToString) Then
                Trg.TargetImgURLSmall = ds.Tables(0).Rows(0).Item("TargetImgURLSmall").ToString
            End If
            If Not IsDBNull(ds.Tables(0).Rows(0).Item("TargetImgURLMedium").ToString) Then
                Trg.TargetImgURLMedium = ds.Tables(0).Rows(0).Item("TargetImgURLMedium").ToString
            End If

            Return Trg
        End If
        Return Nothing
    End Function

End Class
